package com.frank.oj.service.entity.discussion.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.frank.model.entity.discussion.Discussion;
import com.frank.model.entity.msg.MsgRemind;
import com.frank.oj.mapper.DiscussionMapper;
import com.frank.oj.model.vo.DiscussionVO;
import com.frank.oj.service.entity.discussion.DiscussionEntityService;
import com.frank.oj.service.entity.msg.MsgRemindEntityService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author frank
 * @Date 2024/4/7
 */
@Service
public class DiscussionEntityServiceImpl extends ServiceImpl<DiscussionMapper, Discussion> implements DiscussionEntityService {

    @Resource
    private DiscussionMapper discussionMapper;
    @Resource
    private MsgRemindEntityService msgRemindEntityService;

    @Override
    public DiscussionVO getDiscussion(Integer did, String uid) {

        return discussionMapper.getDiscussion(did, uid);
    }

    @Override
    @Async
    public void updatePostLikeMsg(String recipientId, String senderId, Integer did, Long gid) {
        MsgRemind msgRemind = new MsgRemind();
        msgRemind.setAction("Like_Post")
                .setRecipientId(recipientId)
                .setSenderId(senderId)
                .setSourceId(did)
                .setSourceType("Discussion");

        if (gid != null) {
            msgRemind.setUrl("/group/" + gid + "/discussion-detail/" + did);
        } else {
            msgRemind.setUrl("/discussion-detail/" + did);
        }

        msgRemindEntityService.saveOrUpdate(msgRemind);
    }
}
